home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / Snippets / Interapplication Comm. / IPCLister / IPCLister.main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  26.5 KB  |  716 lines  |  [TEXT/MPS ]

  1. /* IPCLister.c */
  2. /* The simplest C System 7 shell application */
  3. /* Modified to show IPCListPorts */
  4. /* March, 1992 */
  5. /* C.K. Haun <TR> */
  6. /* This shell can be very handy for debugging and testing things */
  7. /* Add menu items, add dialogs, add controls, or whatever else you need */
  8. /* This sample contains basic application startup and event loop handling, */
  9. /* add more features as your needs increase. */
  10. /* This sample is High Level Event aware, so you can send and receive AppleEvents */
  11. /* from this application */
  12. /* Written by C.K. Haun <TR> */
  13. /* Apple Developer Tech Support */
  14. /* October 1991, Tokyo, Japan */
  15. /* Of course, Copyright 1991-1992, Apple Computer Inc. */
  16.  
  17. #include <Types.h>
  18. #include <memory.h>
  19. #include <Packages.h>
  20. #include <Errors.h>
  21. #include <quickdraw.h>
  22. #include <fonts.h>
  23. #include <dialogs.h>
  24. #include <windows.h>
  25. #include <menus.h>
  26. #include <events.h>
  27. #include <OSEvents.h>
  28. #include <Desk.h>
  29. #include <diskinit.h>
  30. #include <OSUtils.h>
  31. #include <resources.h>
  32. #include <toolutils.h>
  33. #include <AppleEvents.h>
  34. #include <EPPC.h>
  35. #include <GestaltEqu.h>
  36. #include <PPCToolbox.h> 
  37. #include <Processes.h>
  38. #include <Balloons.h>
  39. #include <ALiases.h>
  40. #include <Processes.h>
  41. #include <StandardFile.h>
  42. #include <Folders.h>
  43. #include <AppleTalk.h> 
  44. #include <Lists.h>
  45. /* prototypes */
  46. void InitalizeApp(void);
  47. void DoDiskEvents(long dinfo);                              /* hi word is error code, lo word is drive number */
  48. void DrawMain(WindowPtr drawIt);
  49. Boolean DoSelected(long val);
  50. void InitAEStuff(void);
  51. void DoHighLevel(EventRecord *AERecord);
  52. void DoDaCall(MenuHandle themenu, long theit);
  53. pascal OSErr AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  54. pascal OSErr AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  55. pascal OSErr AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  56. pascal OSErr AEQuitHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  57. void SampleHelpDialog(void);
  58. void RefreshMacList(ListHandle theList);
  59. void DoIPCListAndFillList(Cell *theCell, ListHandle theList);
  60. void SetContextSwitch(Boolean how);
  61. OSErr myGetMyZone(char *nameBack);
  62.  
  63.  
  64. /*  external */
  65. extern void _DataInit();                                    /* this is the C initialization code */
  66. extern OSErr myIPCListPorts(short theStartIndex, short theRequestCount, short *theActualCount, Str32 theObjStr, Str32 theZoneStr,
  67.                             PortInfoArrayPtr thePortInfoBufferPtr);
  68. extern OSErr GetAllPPCAbleMachines(MPPParamBlock *paramblk);
  69. extern OSErr GetPortsOnMachine();
  70. extern MPPParamBlock paramblk;
  71.  
  72.  
  73.  
  74. enum  {
  75.     kMBarID = 128
  76. };
  77. enum  {
  78.     kAppleMenu = 128, kFileMenu, kEditMenu, kToolsMenu
  79. };
  80. enum  {
  81.     kResumeMask = 1,  /* bit of message field for resume vs. suspend */
  82.     kSampHelp = 129, kAboutBox = 128, kHelpString = 128, kNewItem = 1, kOpenItem, kCloseItem,
  83.     kSaveItem, kSaveAsItem, kFileBlank1,
  84.         kPageSetupItem, kPrintItem, kFileBlank2, kQuitItem, 
  85.         kBadSystem = 130, kGenStrings = 128, kMenuToggleStrings = 129,
  86.         kMyModalKind = 1000, kMyDocumentKind
  87. };
  88. enum  {
  89.     kItem1 = 1, kWaitDialog = 131
  90. };
  91. enum  {
  92.     kCloseIt = 1, kOpenIt
  93. };
  94. /* string IDs for window */
  95. enum  {
  96.     kSayMacs = 2, kSayPorts = 3
  97. };
  98. struct AEinstalls {
  99.     AEEventClass theClass;
  100.     AEEventID theEvent;
  101.     EventHandlerProcPtr theProc;
  102. };
  103. typedef struct AEinstalls AEinstalls;
  104.  
  105. /* some globals */
  106. MenuHandle gAppleMenuHandle, gFileMenuHandle, gEditMenuHandle, gToolMenuHandle;
  107. Boolean gQuit, gInBackground;
  108. EventRecord gERecord;
  109. AEDesc gTheAddress;
  110. ProcessSerialNumber gOurSN;
  111. short gHelpItem;
  112. /* this is our global to tell us if a movable modal is up*/
  113. unsigned long gMySleep = 30;
  114. ListHandle gMacList, gPortsList;
  115.  
  116. #pragma segment Main
  117. main()
  118. {
  119.     WindowPtr twindow;
  120.     UnloadSeg((Ptr)_DataInit);                              /* throw out setup code */
  121.     InitalizeApp();
  122.     UnloadSeg((Ptr)InitalizeApp);   /* get rid of my initialization code */
  123.     do {
  124.         
  125.         WaitNextEvent(everyEvent, &gERecord, gMySleep, nil);
  126.         switch (gERecord.what) {
  127.             ProcPtr drawProc;
  128.             short tempKind;
  129.             case nullEvent:
  130.                 /* no nul processing in this sample */
  131.                 break;
  132.                 
  133.             case updateEvt:
  134.                 tempKind = ((WindowPeek)gERecord.message)->windowKind;
  135.                 /* Mkae sure it's my window before I jump through the refCon */
  136.                 /* Why, since DA's have they're own layer in 7.0? */
  137.                 /* BECAUSE there are other people in the universe who will */
  138.                 /* add things to your windowList.BalloonWriter, for example, */
  139.                 /* so you still need to be careful */
  140.                 if (tempKind == kMyModalKind || tempKind == kMyDocumentKind) {
  141.                     /* get the drawing proc from the refCon */
  142.                     drawProc = (ProcPtr)GetWRefCon((WindowPtr)gERecord.message);
  143.                     /* jump to it */
  144.                     drawProc((WindowPtr)gERecord.message);
  145.                 }
  146.                 break;
  147.                 
  148.             case mouseDown:
  149.                 /* first see where the hit was */
  150.                 
  151.                 switch (FindWindow(gERecord.where, &twindow)) {
  152.                     
  153.                     case inDesk:                            /* if they hit in desk, then the process manager */
  154.                         break;                              /* will switch us out, we don't need to do anything */
  155.                         
  156.                     case inMenuBar:
  157.                         /* let Help and Application menus happen always */
  158.                         DoSelected(MenuSelect(gERecord.where));
  159.                         break;
  160.                         
  161.                     case inSysWindow:
  162.                         /* pass to the system */
  163.                         SystemClick(&gERecord, twindow);
  164.                         break;
  165.                         
  166.                     case inContent:
  167.                         /* Handle content and control clicks here */
  168.                         /* If they clicked in the content region of a back window, */
  169.                         /* bring that window forward */
  170.                         if (twindow != FrontWindow()) {                            
  171.                             SelectWindow(twindow);          /* select the window */
  172.                             SetPort(twindow);                            
  173.                         } else {
  174.                             /* control tracking or whatever. */
  175.                             /* Here we have a couple of lists, so we'll track */
  176.                             /* them */
  177.                             short hit;
  178.                             Rect boundRect;
  179.                             Point locPoint = gERecord.where;
  180.                             ControlHandle returnedControl;
  181.                             GlobalToLocal(&locPoint);
  182.                             /* first see if it's in eiher of our Lists */
  183.                             boundRect = (*gMacList)->rView;
  184.                             /* expand to include the scroll bear */
  185.                             boundRect.right += 15;
  186.                             if (PtInRect(locPoint, &boundRect)) {
  187.                                 Cell currentCell =  {
  188.                                     0, 0
  189.                                 };
  190.                                 Cell theCell =  {
  191.                                     0, 0
  192.                                 };
  193.                                 /* first, get the current cell */
  194.                                 LGetSelect(true, ¤tCell, gMacList);
  195.                                 if (LClick(locPoint, nil, gMacList)) {                                    
  196.                                     /* if it's in this list, switch port list */
  197.                                     if (LGetSelect(true, &theCell, gMacList)) {
  198.                                         /* this is where you'd do something special for a double-click */
  199.                                         /* in this example I just fill the other list in agin */
  200.                                         DoIPCListAndFillList(&theCell, gPortsList);
  201.                                     }
  202.                                 } else {
  203.                                     /* single click, but maybe they changed things */
  204.                                     LGetSelect(true, &theCell, gMacList);
  205.                                     if (theCell.v != currentCell.v)
  206.                                         DoIPCListAndFillList(&theCell, gPortsList);
  207.                                 }
  208.                             } else {
  209.                                 boundRect = (*gPortsList)->rView;
  210.                                 /* expand to include the scroll bear */
  211.                                 boundRect.right += 15;
  212.                                 
  213.                                 if (PtInRect(locPoint, &boundRect)) {
  214.                                     LClick(locPoint, nil, gPortsList);
  215.                                     /* if it's in this list, I just don't care atall */
  216.                                 } else {
  217.                                     /* normal control tracking goes here, commented out */
  218.                                     /* since I'm not using it today */
  219.                                     /*
  220.                                     if (FindControl(locPoint, twindow, &returnedControl)) {
  221.                                     if (TrackControl(returnedControl, locPoint, nil)) {
  222.                                     
  223.                                     }
  224.                                     } */
  225.                                 }
  226.                             }
  227.                         }
  228.                         break;
  229.                         
  230.                     case inDrag:
  231.                         DragWindow(twindow, gERecord.where, &qd.screenBits.bounds);
  232.                         break;
  233.                         
  234.                     case inGrow:
  235.                         /* Call GrowWindow here if you have a grow box */
  236.                         break;
  237.                         
  238.                     case inGoAway:
  239.                         /* Click in Close box */
  240.                         break;
  241.                 }
  242.             case mouseUp:
  243.                 /* don't care */
  244.                 break;
  245.                 /* same action for key or auto key */
  246.             case keyDown:
  247.             case autoKey:
  248.                 if (gERecord.modifiers & cmdKey)
  249.                     DoSelected(MenuKey(gERecord.message & charCodeMask));
  250.                 break;
  251.                 
  252.             case keyUp:
  253.                 /* don't care */
  254.                 break;
  255.                 
  256.             case diskEvt:
  257.                 /* I don't do anything special for disk events, this just passes them */
  258.                 /* to a function that checks for an error on the mount */
  259.                 DoDiskEvents(gERecord.message);
  260.                 break;
  261.                 
  262.             case activateEvt:
  263.                 /* not doing anything on activates */
  264.                 break;
  265.                 
  266.             case networkEvt:
  267.                 /* don't care */
  268.                 break;
  269.                 
  270.             case driverEvt:
  271.                 /* don't care */
  272.                 break;
  273.                 
  274.             case app4Evt:
  275.                 /* If we're switching layers and I have my MModal up, I want to */
  276.                 /* change the state of the control */
  277.                 switch ((gERecord.message >> 24) & 0x0FF) {     /* high byte of message */
  278.                     
  279.                     case suspendResumeMessage:              /* suspend/resume is also an activate/deactivate */
  280.                         gInBackground = (gERecord.message & kResumeMask) == 0;
  281.                         /* set dim/enable on the control */
  282.                         /* make sure hiliting is right */
  283.                         SetContextSwitch(gInBackground);
  284.                         break;
  285.                         
  286.                 }
  287.                 break;
  288.                 
  289.                 /* This dispatches high level events (AppleEvents, for example) */
  290.                 /* to our dispatch routine.This is NEW in the event loop for */
  291.                 /* System 7 */
  292.             case kHighLevelEvent:
  293.                 DoHighLevel(&gERecord);
  294.                 break;
  295.             default:
  296.                 break;
  297.                 
  298.         }
  299.     }
  300.             while (gQuit != true);
  301. }
  302.  
  303. /* DoDaCall opens the requested DA.It's here as a seperate routine if you'd */
  304. /* like to perform some action or just know when a DA is opened in your */
  305. /* layer.Can be handy to track memory problems when a DA is opened */
  306. /* with an Option-open */
  307. void DoDaCall(MenuHandle themenu, long theit)
  308. {
  309.     long qq;
  310.     char DAname[255];
  311.     GetItem(themenu, theit, &DAname);
  312.     qq = OpenDeskAcc(DAname);
  313. }
  314.  
  315. /* end DoDaCall */
  316.  
  317. /* DoDiskEvents just checks the error code from the disk mount, */
  318. /* and puts up the 'Format' dialog (through DIBadMount) if need be */
  319. /* You can do much more here if you care about what disks are */
  320. /* in the drive */
  321. void DoDiskEvents(long dinfo)                               /* hi word is error code, lo word is drive number */
  322. {
  323.     short hival, loval, tommy;
  324.     Point fredpoint =  {
  325.         40, 40
  326.     };
  327.     hival = HiWord(dinfo);
  328.     loval = LoWord(dinfo);
  329.     if (hival != noErr)                                     /* something happened */ {
  330.         tommy = DIBadMount(fredpoint, dinfo);
  331.     }
  332. }
  333.  
  334. /* draws my window.Pretty simple */
  335. void DrawMain(WindowPtr drawIt)
  336. {
  337.     WindowPtr tempWP;
  338.     Str255 words;
  339.     Rect tempRect;
  340.     GetPort(&tempWP);
  341.     BeginUpdate(drawIt);
  342.     SetPort(drawIt);
  343.     EraseRect(&drawIt->portRect);
  344.     LUpdate(drawIt->visRgn, gMacList);
  345.     tempRect = (*gMacList)->rView;
  346.     InsetRect(&tempRect, -2, -1);
  347.     FrameRect(&tempRect);
  348.     MoveTo(tempRect.left, tempRect.top - 2);
  349.     GetIndString(words, kGenStrings, kSayMacs);
  350.     DrawString(words);
  351.     /* other list */
  352.     LUpdate(drawIt->visRgn, gPortsList);
  353.     tempRect = (*gPortsList)->rView;
  354.     InsetRect(&tempRect, -2, -1);
  355.     FrameRect(&tempRect);
  356.     MoveTo(tempRect.left, tempRect.top - 2);
  357.     GetIndString(words, kGenStrings, kSayPorts);
  358.     DrawString(words);
  359.     
  360.     EndUpdate(drawIt);
  361.     SetPort(tempWP);
  362. }
  363.  
  364. /* my menu action taker.It returns a Boolean which I usually ignore, but it */
  365. /* mught be handy someday */
  366. Boolean DoSelected(long val)
  367. {
  368.     short loval, hival;
  369.     Boolean returnVal = false;
  370.     loval = LoWord(val);
  371.     hival = HiWord(val);
  372.     
  373.     switch (hival) {                                        /* switch off the menu number selected */
  374.         case kAppleMenu:                                    /* Apple menu */
  375.             if (loval != 1) {                               /* if this was not About, it's a DA */
  376.                 DoDaCall(gAppleMenuHandle, loval);
  377.             } else {
  378.                 Alert(kAboutBox, nil);                      /* do about box */
  379.             }
  380.             returnVal = true;
  381.             break;
  382.         case kFileMenu:                                     /* File menu */
  383.             switch (loval) {
  384.                 case kQuitItem:
  385.                     gQuit = true;                           /* onlyitem */
  386.                     returnVal = true;
  387.                     break;
  388.                 default:
  389.                     break;
  390.             }
  391.             break;
  392.             
  393.         case kEditMenu:
  394.             /* edit menu junk */
  395.             /* don't care */
  396.             break;
  397.             
  398.         case kToolsMenu:
  399.             /* add all your test stuff here */
  400.             RefreshMacList(gMacList);
  401.             break;
  402.             
  403.         case kHMHelpMenuID:                                 /* Defined in Balloons.h */
  404.             /* I only care about this item.If anything else is returned here, I don't know what */
  405.             /* it is, so I leave it alone.Remember, the Help Manager chapter says that */
  406.             /* Apple reserves the right to add and change things in the Help menu */
  407.             if (loval == gHelpItem)
  408.                 SampleHelpDialog();
  409.             break;
  410.             
  411.     }
  412.     HiliteMenu(0);
  413.     return(returnVal);
  414. }
  415.  
  416. /* InitAEStuff installs my appleevent handlers */
  417. void InitAEStuff(void)
  418. {
  419.     static AEinstalls HandlersToInstall[] =  {
  420.         {
  421.             kCoreEventClass, kAEOpenApplication, AEOpenHandler
  422.         },  {
  423.             kCoreEventClass, kAEOpenDocuments, AEOpenDocHandler
  424.         },  {
  425.             kCoreEventClass, kAEQuitApplication, AEQuitHandler
  426.         },  {
  427.             kCoreEventClass, kAEPrintDocuments, AEPrintHandler
  428.         }, 
  429.         /* The above are the four required AppleEvents. */
  430.         
  431.     };
  432.     
  433.     OSErr aevtErr = noErr;
  434.     long aLong = 0;
  435.     Boolean gHasAppleEvents = false;
  436.     /* Check this machine for AppleEvents.If they are not here (ie not 7.0)
  437.     * then we exit */
  438.     gHasAppleEvents = (Gestalt(gestaltAppleEventsAttr, &aLong) == noErr);
  439.     /* The following series of calls installs all our AppleEvent Handlers.
  440.     * These handlers are added to the application event handler list that 
  441.     * the AppleEvent manager maintains.So, whenever an AppleEvent happens
  442.     * and we call AEProcessEvent, the AppleEvent manager will check our
  443.     * list of handlers and dispatch to it if there is one.
  444.     */
  445.     if (gHasAppleEvents) {
  446.         register qq;
  447.         for (qq = 0; qq < ((sizeof(HandlersToInstall) / sizeof(AEinstalls))); qq++) {
  448.             aevtErr = AEInstallEventHandler(HandlersToInstall[qq].theClass, HandlersToInstall[qq].theEvent,
  449.                                             HandlersToInstall[qq].theProc, 0, false);
  450.             if (aevtErr) {
  451.                 ExitToShell();                              /* just fail, baby */
  452.             }
  453.         }
  454.     } else {
  455.         ExitToShell();
  456.     }
  457. }
  458.  
  459. /* end InitAEStuff */
  460. /* I'm not doing error handling in this sample for clarities sake, you should. Hah, */
  461. /* easy for me to say, huh? */
  462. void DoHighLevel(EventRecord *AERecord)
  463. {
  464.     
  465.     AEProcessAppleEvent(AERecord);
  466.     
  467. }
  468.  
  469. /* end DoHighLevel */
  470.  
  471. /* This is the standard Open Application event.*/
  472. pascal OSErr AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  473. {
  474. #pragma unused (messagein,reply,refIn)
  475.  
  476.     Rect lRect;
  477.     Rect lRect2 =  {
  478.         0, 0, 0, 1
  479.     };
  480.     Point cp =  {
  481.         0, 0
  482.     };
  483.     
  484.     short theSize;
  485.     FontInfo theFont;
  486.     typedef unsigned char Tuple[104];
  487.     extern Tuple myRetBuff[100];
  488.     WindowPtr myWindow;
  489.     /* we of course don't do anything here in this simple app */
  490.     /* except open our window */
  491.     myWindow = GetNewWindow(128, nil, (WindowPtr)-1);
  492.     ((WindowPeek)myWindow)->windowKind = kMyDocumentKind;
  493.     /* install drawing proc */
  494.     SetWRefCon(myWindow, (long)DrawMain);
  495.     
  496.     /* add two lists */
  497.     SelectWindow(myWindow);
  498.     SetPort(myWindow);
  499.     /* call the draw proc oncet */
  500.     GetFontInfo(&theFont);
  501.     theSize = (theFont.ascent + theFont.descent + theFont.leading) * 10;
  502.     SetRect(&lRect, 10, 30, (myWindow->portRect.right / 2) - 15, 30 + theSize);
  503.     gMacList = LNew(&lRect, &lRect2, cp, nil, myWindow, true, false, false, true);
  504.     LActivate(true, gMacList);
  505.     LDoDraw(false, gMacList);
  506.     (*gMacList)->listFlags = lDoVAutoscroll;
  507.     SetRect(&lRect, (myWindow->portRect.right / 2) + 15, 30, (myWindow->portRect.right) - 15, 30 + theSize);
  508.     
  509.     gPortsList = LNew(&lRect, &lRect2, cp, nil, myWindow, true, false, false, true);
  510.     LActivate(true, gPortsList);
  511.     LDoDraw(false, gPortsList);
  512.     (*gPortsList)->listFlags = lDoVAutoscroll;
  513.     /* While we're here we may as well find and add all the PPC capable macs in my zone */
  514.     DrawMain(myWindow);
  515.     
  516.     RefreshMacList(gMacList);
  517.     
  518.     return(noErr);
  519.     
  520. }
  521.  
  522. /* end AEOpenHandler */
  523.  
  524. /* Open Doc, opens our documents.Remember, this can happen at application start AND */
  525. /* anytime else.If your app is up and running and the user goes to the desktop, hilites one */
  526. /* of your files, and double-clicks or selects Open from the finder File menu this event */
  527. /* handler will get called. Which means you don't do any initialization of globals here, or */
  528. /* anything else except open then doc.*/
  529. /* SO-- Do NOT assume that you are at app start time in this */
  530. /* routine, or bad things will surely happen to you. */
  531.  
  532. pascal OSErr AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  533. {
  534. #pragma unused (messagein,refIn,reply)
  535.     /* we of course don't do anything here */
  536.     return(errAEEventNotHandled);                           /* we have no docs, so no odoc events should come to us */
  537. }
  538.  
  539. pascal OSErr AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  540. {                                                           /* no printing handler in yet, so we'll ignore this */
  541.     /* the operation is functionally identical to the ODOC event, with the additon */
  542.     /* of calling your print routine.*/
  543. #pragma unused (messagein,refIn,reply)
  544.     /* we of course don't do anything here */
  545.     return(errAEEventNotHandled);                           /* we have no docs, so no pdoc events should come to us */
  546. }
  547.  
  548. /* Standard Quit event handler, to handle a Quit event from the Finder, for example.*/
  549. /* ••••• DO NOT CALL EXITTOSHELL HERE ••••• or you will never have a happy life.*/
  550. pascal OSErr AEQuitHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  551. {
  552. #pragma unused (messagein,refIn,reply)
  553.     
  554.     /* prepQuit sets the Stop flag for us.It does _NOT_ quit, you */
  555.     /* should NEVER quit from an AppleEvent handler.Calling */
  556.     /* ExitToShell here would blow things up */
  557.     gQuit = true;
  558.     return(noErr);
  559. }
  560.  
  561. /* This is my sample help dialog.Does not do anything, expand as you need */
  562. void SampleHelpDialog(void)
  563. {
  564.     DialogPtr tdial = GetNewDialog(kSampHelp, nil, (WindowPtr)-1);
  565.     short itemhit = 0;
  566.     while (itemhit != 1) {
  567.         ModalDialog((ModalFilterProcPtr)nil, &itemhit);
  568.     }
  569.     DisposDialog(tdial);
  570. }
  571.  
  572.  
  573. /* myGetMyZone returns (oh, you guessed!) a zone name string */
  574. OSErr myGetMyZone(char *nameBack)
  575. {
  576.     OSErr myErr = noErr;
  577.     XPPParamBlock *theParamPtr = (XPPParamBlock *)NewPtrClear(sizeof(XPPParamBlock));
  578.     theParamPtr->XCALL.xppTimeout = 3;
  579.     theParamPtr->XCALL.xppRetry = 4;
  580.     theParamPtr->XCALL.zipBuffPtr = nameBack;
  581.     theParamPtr->XCALL.zipInfoField[1] = 0;
  582.     theParamPtr->XCALL.zipInfoField[2] = 0;
  583.     myErr = GetMyZone(theParamPtr, false);
  584.     DisposPtr((Ptr)theParamPtr);
  585.     return(myErr);
  586. }
  587.  
  588. /* RefreshMacList re-scans the current zone for all macs, and */
  589. /* adds them to the list */
  590. void RefreshMacList(ListHandle theList)
  591. {
  592.     register qq;
  593.     Cell cp =  {
  594.         0, 0
  595.     };
  596.     /* This takes a while here at Apple (lotsa machines) so I'll put up a wait dialog */
  597.     DialogPtr theDial = GetNewDialog(kWaitDialog, nil, (WindowPtr)-1);
  598.     DrawDialog(theDial);
  599.     /* this takes a while */
  600.     SetCursor(*GetCursor(watchCursor));
  601.     /* Delete all the current list entries quickly */
  602.     LDelRow(32000, 0, theList);
  603.     /* fill in the list of machines */
  604.     GetAllPPCAbleMachines(¶mblk);
  605.     /* loop through all the machines in this zone and add 'em to the list */
  606.     for (qq = 0; qq < paramblk.NBP.parm.Lookup.numGotten; qq++) {
  607.         EntityName myEntityName;
  608.         AddrBlock myAddrBlock;   
  609.         
  610.         LAddRow(1, qq, theList);    /* a new item, add a row for it */
  611.         cp.v = qq;
  612.         /* get the info out of the NBP record.  It's easier than calculating the offsets */
  613.         /* yerself */
  614.         NBPExtract((Ptr)&myRetBuff, paramblk.NBP.parm.Lookup.numGotten, qq + 1, &myEntityName, &myAddrBlock);
  615.         /* and add this name to the list */
  616.         LAddToCell((&myEntityName.objStr[1]), myEntityName.objStr[0], cp, theList);
  617.     }
  618.     /* kill my wait dialog */
  619.     DisposDialog(theDial);
  620.     InitCursor();
  621. }
  622.  
  623. /* DoIPCListAndFillList calls IPCListPorts for the machine name selected, and  */
  624. /* fills our list with the ports on the other machine */
  625. void DoIPCListAndFillList(Cell *theCell, ListHandle theList)
  626. {
  627.     PortInfoArrayPtr thePorts;
  628.     short returnedCount;
  629.     OSErr myErr = noErr;
  630.     Cell cp =  {
  631.         0, 0
  632.     };
  633.     EntityName myEntityName;
  634.     AddrBlock myAddrBlock;                                  /* myAddrBlock: AddrBlock; */
  635.     register qq;
  636.     SetCursor(*GetCursor(watchCursor));
  637.     /* I want to get a maximum of 30 ports, so allocate a buffer that big */    
  638.     thePorts = (PortInfoArrayPtr)NewPtrClear(sizeof(PortInfoRec) * 30);
  639.     /* extract the machine name and zone name based on the cell they clicked  */
  640.     /* on and the buffer we got from GetAllPPCAbleMachines */
  641.     NBPExtract((Ptr)&myRetBuff, paramblk.NBP.parm.Lookup.numGotten, theCell->v + 1, &myEntityName, &myAddrBlock);
  642.     /* call our IPCList routine */
  643.     myErr = myIPCListPorts(0, 30, &returnedCount, myEntityName.objStr, myEntityName.zoneStr, thePorts);
  644.     if(myErr == noErr){
  645.         /* now add the names to the list */
  646.         LDelRow(32000, 0, theList);
  647.         for (qq = 0; qq < returnedCount; qq++) {
  648.             LAddRow(1, qq, theList);
  649.             cp.v = qq;            
  650.             LAddToCell(&(((PortInfoPtr)thePorts)->name.name[1]), thePorts->name.name[0], cp, theList);
  651.             thePorts = thePorts + 1;            
  652.         }
  653.     }
  654.     DisposPtr((Ptr)thePorts);
  655.     InitCursor();
  656. }
  657.  
  658. /* SetContextSwitch does what I need to do to go into/come out of */
  659. /* the backgrounmd.  In this example, all I do is set the lists */
  660. void SetContextSwitch(Boolean how)
  661. {
  662. how = (how ? false:true); /* don't ask, The how is kinda backwards */
  663.     LActivate(how,gMacList);
  664.     LActivate(how,gPortsList);
  665. }
  666.  
  667. #pragma segment Init
  668. void InitalizeApp(void)
  669. {
  670.     MenuHandle helpHandle;
  671.     Handle myMenu;
  672.     StringHandle helpString;
  673.     short count;
  674.     long vers;
  675.     MaxApplZone();
  676.     InitGraf((Ptr)&qd.thePort);
  677.     InitFonts();
  678.     InitWindows();
  679.     InitMenus();
  680.     TEInit();
  681.     InitDialogs(nil);
  682.     InitCursor();
  683.     /* Check system version */
  684.     Gestalt(gestaltSystemVersion, &vers);
  685.     vers = (vers >> 8) & 0xf;                               /* shift result over and mask out major version number */
  686.     if (vers < 7) {
  687.         StopAlert(kBadSystem, nil);
  688.         ExitToShell();
  689.     }
  690.     PPCInit();
  691.     InitAEStuff();
  692.     
  693.     /* set up my menu junk */
  694.     myMenu = GetNewMBar(kMBarID);
  695.     SetMenuBar(myMenu);
  696.     gAppleMenuHandle = GetMHandle(kAppleMenu);
  697.     gFileMenuHandle = GetMHandle(kFileMenu);
  698.     gEditMenuHandle = GetMHandle(kEditMenu);
  699.     gToolMenuHandle = GetMHandle(kToolsMenu);
  700.     AddResMenu(gAppleMenuHandle, 'DRVR');
  701.     /* now install my Help menu item in the Help Manager's menu */
  702.     HMGetHelpMenuHandle(&helpHandle);                       /* Get the Hlpe menu handle */
  703.     count = CountMItems(helpHandle);                        /* How many items are there? */
  704.     helpString = GetString(kHelpString);                    /* get my help string */
  705.     DetachResource(helpString);                             /* detach it */
  706.     HNoPurge(helpString);
  707.     MoveHHi((Handle)helpString);
  708.     HLock((Handle)helpString);
  709.     InsMenuItem(helpHandle, (Ptr)*helpString, count + 1);       /* insert my item in the Help menu */
  710.     gHelpItem = CountMItems(helpHandle);                    /* The number of the item */
  711.     
  712.     DrawMenuBar();
  713.     GetCurrentProcess(&gOurSN);                             /* Get our process serial number for later use, if needed */
  714.     
  715. }
  716.